package com.zuoban.controller;

import com.zuoban.common.Result;
import com.zuoban.dto.UserLoginDto;
import com.zuoban.service.BaseUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Api(tags = "用户信息")
@RestController
@RequestMapping("/userinfo")
@RequiredArgsConstructor
public class BaseUserInfoController {

    private final BaseUserInfoService baseUserInfoService;

    @ApiOperation("注册")
    @PostMapping("/register")
    public Result register(@RequestBody UserLoginDto userLoginDto){
        return baseUserInfoService.register(userLoginDto);
    }

    @ApiOperation("获取图片验证码")
    @GetMapping("/getImgCode")
    public void getImgCode(@RequestParam("userAccount") String userAccount, HttpServletResponse response){
        baseUserInfoService.getImgCode(userAccount, response);
    }

    @ApiOperation("登录")
    @PostMapping("/login")
    public Result login(HttpServletRequest request, @RequestBody UserLoginDto userLoginDto){
        return baseUserInfoService.login(request,userLoginDto);
    }

    @ApiOperation("退出")
    @PostMapping("logout")
    public void logout(@RequestBody UserLoginDto userLoginDto){
        baseUserInfoService.logout(userLoginDto);
    }
}
